#pragma once

#include <gtl/string/str.h>

class CClipboard
{
public:
	CClipboard()
	{
	}

public:
	template<class Char>
	bool Copy(const Char* pszText)
	{
		if(pszText == NULL || !::OpenClipboard(NULL))
			return false;

		::EmptyClipboard();

		gtl::wstr_warp text(pszText);
		size_t len = text.length();
		HGLOBAL hGlbCopy = GlobalAlloc(GMEM_MOVEABLE, (len + 1) * sizeof(wchar_t));
		if(hGlbCopy == NULL)
		{
			::CloseClipboard();
			return false;
		}

		Char* lpszCopy = (TCHAR*)GlobalLock(hGlbCopy);
		memcpy(lpszCopy, pszText, len * sizeof(wchar_t));
		lpszCopy[len] = 0;
		GlobalUnlock(lpszCopy);

		SetClipboardData(CF_UNICODETEXT, hGlbCopy);
		::CloseClipboard();

		return true;
	}

	bool Copy(HBITMAP hBitmap)
	{
		if(hBitmap == NULL || ::OpenClipboard(NULL))
			return false;

		::EmptyClipboard();
		SetClipboardData(CF_BITMAP, hBitmap);
		::CloseClipboard();

		return true;
	}
};